<?php
$getPackagePrice = Yii::$app->params['getPackagePrice']; //价格
$getCateGory     = Yii::$app->params['getCateGory']; //类别
$getPakcageState = Yii::$app->params['package_state']; //状态
$getPackageType = Yii::$app->params['getPackageType']; //类型industrys
$industrys = Yii::$app->params['industrys']; //所属行业
$provinceData = $provinceData; //省
?>
<div class="clearfix options-content-form">
    <a href="/search-all/?postion=2&keyWords=" style="color: #2194f1;float: right;font-size: 14px;margin-right: 100px;">清除查询条件</a>
</div>
    <!-- 本金数额 -->
<div class="clearfix options-content-form">
    <label for="" class="pull-left control-label">本金数额</label>
    <?php
        $principal = Yii::$app->request->get('principal',0);
        foreach ($getPackagePrice as $k => $v){
            $priceName  = $v['name'];
            if ($k == $principal){
                echo <<<PRICE
    <span class='active pricePackageSearch' data-val="$k">$priceName</span>
PRICE;
            }else{
                echo <<<PRICE
    <span class='pricePackageSearch' data-val="$k">$priceName</span>
PRICE;
            }

        }
    ?>
</div>
<!-- 2.资产包类别 -->
<div class="clearfix options-content-form">
    <label for="" class="pull-left control-label">资产包类别</label>
    <?php
    $category = Yii::$app->request->get('category',0);
    foreach ($getCateGory as $k => $v){
        $priceName  = $v['name'];
        if ($k == $category){
            echo <<<PRICE
    <span class='active catePackageSearch' data-val="$k">$priceName</span>
PRICE;
        }else{
            echo <<<PRICE
    <span class='catePackageSearch' data-val="$k">$priceName</span>
PRICE;
        }
    }
    ?>
</div>
<!-- 3.当前状态 -->
<div class="clearfix options-content-form">
    <label for="" class="pull-left control-label">当前状态</label>
    <?php
   $dangqianzhuangtai =  Yii::$app->request->get('packageState',0);
   $dangqianzhuangtai = !empty($dangqianzhuangtai) && $dangqianzhuangtai!=0 ?$dangqianzhuangtai:0;
   if ($dangqianzhuangtai==0){
       echo "<span class='active statePackageSearch' data-val='0'>全部</span>";
   }else{
       echo "<span class='statePackageSearch' data-val='0'>全部</span>";
   }
    foreach ($getPakcageState as $k => $v){
        $priceName  = $v;
        $val = $k;
        if ($k == $dangqianzhuangtai){
            echo <<<PRICE
    <span class='active statePackageSearch' data-val="$val">$priceName</span>
PRICE;
        }else{
            echo <<<PRICE
    <span class='statePackageSearch' data-val="$val">$priceName</span>
PRICE;
        }
    }
    ?>
</div>
<!-- 4.资产包类型 -->
<div class="clearfix options-content-form">
    <label for="" class="pull-left control-label">资产包类型</label>
    <?php
    $zichanleixing = Yii::$app->request->get('packageType',0);
    foreach ($getPackageType as $k => $v){
        $priceName  = $v['name'];
        if ($k == $zichanleixing){
            echo <<<PRICE
    <span class='active typePackageSearch' data-val="$k">$priceName</span>
PRICE;
        }else{
            echo <<<PRICE
    <span class='typePackageSearch' data-val="$k">$priceName</span>
PRICE;
        }
    }
    ?>
</div>
<!-- 5.省份地区 -->
<div class="clearfix options-content-form">
    <label for="" class="pull-left control-label">省份地区</label>
    <div class="options-content-form-list pull-right">
        <?php
        $province = Yii::$app->request->get('province',0);
        if (!empty($provinceData) && is_array($provinceData)){
        foreach ($provinceData as $k => $v){
            $title  = $v['title'];
            $id = $v['id'];
            if ($id == 3553 && $province == 0){
                echo <<<PRICE
            <span class='active provincePacjage ' data-val="0">$title</span>
PRICE;
            }elseif ($id == 3553){
                echo <<<PRICE1
            <span class='provincePacjage ' data-val="0">$title</span>
PRICE1;
            }
        }
        foreach ($provinceData as $k => $v){
            $title  = $v['title'];
            $id = $v['id'];
            if ($id!=3553 && $id == $province){
                echo <<<PRICE
            <span class='active provincePacjage' data-val="$id">$title</span>
PRICE;
            }else if ($id!=3553){
                echo <<<PRICE
            <span class='provincePacjage' data-val="$id">$title</span>
PRICE;
            }
        }
        }
        ?>
    </div>
    <div class="options-content-form-list2 pull-right" id="city">
    </div>

</div>
<!--6. 行业分类 -->
<div class="clearfix options-content-form options-content-form2" id="industrysTag">
    <label for="" class="pull-left control-label mb40">行业分类</label>
    <?php
    $industry = explode(",",Yii::$app->request->get("industry",","));
    if (!empty($industry)){
        echo '<span class="industrysPackageSearchAll" data-val="0">全部</span>';
    }else{
        echo '<span class="industrysPackageSearchAll active" data-val="0">全部</span>';
    }
    foreach ($industrys as $k => $v){
        $name  = $v['name'];
        $val = $v['val'];
        if (in_array($val,$industry)){
            echo <<<PRICE
            <span class="industrysPackageSearch active" data-val="$val">$name</span>
PRICE;
        }else{
            echo <<<PRICE
            <span class="industrysPackageSearch" data-val="$val">$name</span>
PRICE;
        }

    }
    ?>
</div>

<script>
    $(function () {
        //--------------start-----------fly----------------------
        //点击省份加载城市
        $(".provincePacjage").click(function () {
            city = 0;
            var provinceId = $(this).data('val');
            province = provinceId;
            $.get('/search-package/ajax-city',{'provinceID':provinceId},function (res) {
                var resData = JSON.parse( res );
                if (resData.code==200){
                    readringCity(resData.data.res);
                    var url = "/search-all/?keyWords="+keyWords+"&principal="+principal+'&category='+zichanbaobei+"&packageState="+dangqianzhuangtai+"&packageType="+zichanleixing+"&owner="+shangchuanren+"&teams="+tuandui+"&leader="+zongjian+"&province="+province+"&city="+city+'&limit='+pageNumThis+'&entry=sala&postion=2'+'&is_title='+is_title;
                    window.location.href = url;
                }else{
                    layer.msg("错误")
                }
            })
        })
        //刷新页面加载城市数据
        getProvinceID = '<?= $province ?>';
        $().ready(function(){
            if (getProvinceID != 0){
                $.get('/search-package/ajax-city',{'provinceID':getProvinceID},function (res) {
                    var resData = JSON.parse( res );
                    console.log(resData);
                    if (resData.code==200){
                        readringCity(resData.data.res);
                    }else{
                        layer.msg("错误")
                    }
                })
            }else{
                $("#city").hide();
            }
        })
        //渲染城市
        function readringCity(resData) {
            cityId = '<?=Yii::$app->request->get("city",0)?>';
            var cityHtml = "";
            if (cityId == 0){
                cityHtml = "<span class='active cityPackageSearch' data-val='0'>全部</span>";
            }else{
                cityHtml = "<span class='cityPackageSearch' data-val='0'>全部</span>";
            }
            $(resData).each(function(i,e){
                var title = e.title;
                var id    = e.id;
                if (cityId == id){
                    cityHtml+= "<span class='active cityPackageSearch'  data-val='"+id+"'>"+title+"</span>";
                }else{
                    cityHtml+= "<span class='cityPackageSearch'  data-val='"+id+"'>"+title+"</span>";
                }
            });
            $("#city").html("");
            $("#city").append(cityHtml);
        }
        //组织条件搜索
        //价格
        $(".pricePackageSearch").click(function () {
            principal = $(this).data('val');
            var url = "/search-all/?keyWords="+keyWords+"&principal="+principal+'&category='+zichanbaobei+"&packageState="+dangqianzhuangtai+"&packageType="+zichanleixing+"&owner="+shangchuanren+"&teams="+tuandui+"&leader="+zongjian+"&province="+province+"&city="+city+'&limit='+pageNumThis+'&industry='+industry+'&order='+orderP+'&entry=sala&postion=2'+'&is_title='+is_title;
            window.location.href = url;
        })
        //类别
        $(".catePackageSearch").click(function () {
            zichanbaobei = $(this).data('val');
            var url = "/search-all/?keyWords="+keyWords+"&principal="+principal+'&category='+zichanbaobei+"&packageState="+dangqianzhuangtai+"&packageType="+zichanleixing+"&owner="+shangchuanren+"&teams="+tuandui+"&leader="+zongjian+"&province="+province+"&city="+city+'&limit='+pageNumThis+'&industry='+industry+'&order='+orderP+'&entry=sala&postion=2'+'&is_title='+is_title;
            window.location.href = url;
        })
        //状态
        $(".statePackageSearch").click(function () {
            dangqianzhuangtai = $(this).data('val');
            var url = "/search-all/?keyWords="+keyWords+"&principal="+principal+'&category='+zichanbaobei+"&packageState="+dangqianzhuangtai+"&packageType="+zichanleixing+"&owner="+shangchuanren+"&teams="+tuandui+"&leader="+zongjian+"&province="+province+"&city="+city+'&limit='+pageNumThis+'&industry='+industry+'&order='+orderP+'&entry=sala&postion=2'+'&is_title='+is_title;
            window.location.href = url;
        })
        //类型
        $(".typePackageSearch").click(function () {
            zichanleixing = $(this).data('val');
            var url = "/search-all/?keyWords="+keyWords+"&principal="+principal+'&category='+zichanbaobei+"&packageState="+dangqianzhuangtai+"&packageType="+zichanleixing+"&owner="+shangchuanren+"&teams="+tuandui+"&leader="+zongjian+"&province="+province+"&city="+city+'&limit='+pageNumThis+'&industry='+industry+'&order='+orderP+'&entry=sala&postion=2'+'&is_title='+is_title;
            window.location.href = url;
        })
        //城市
        $(document).on('click','.cityPackageSearch',function () {
            city = $(this).data('val');
            var url = "/search-all/?keyWords="+keyWords+"&principal="+principal+'&category='+zichanbaobei+"&packageState="+dangqianzhuangtai+"&packageType="+zichanleixing+"&owner="+shangchuanren+"&teams="+tuandui+"&leader="+zongjian+"&province="+province+"&city="+city+'&limit='+pageNumThis+'&industry='+industry+'&order='+orderP+'&entry=sala&postion=2'+'&is_title='+is_title;
            window.location.href = url;
        })
        //行业分类
        $(".industrysPackageSearch").click(function () {
            //判断是否选中，如果选中则取消
            if ($(this).hasClass("active")){
                $(this).removeClass("active");
            }else{
                $(this).addClass("active");
            }
            industry = ',';
            $("#industrysTag span").each(function(){
                var industrysClass = $(this).attr('class');
                if (industrysClass == 'industrysPackageSearch active'){
                    industry = industry+$(this).data('val')+',';
                }
            });
            if (industry == ','){
                industry = '';
            }
            var url = "/search-all/?keyWords="+keyWords+"&principal="+principal+'&category='+zichanbaobei+"&packageState="+dangqianzhuangtai+"&packageType="+zichanleixing+"&owner="+shangchuanren+"&teams="+tuandui+"&leader="+zongjian+"&province="+province+"&city="+city+'&limit='+pageNumThis+'&industry='+industry+'&order='+orderP+'&entry=sala&postion=2'+'&is_title='+is_title;
            window.location.href = url;
        })
        //行业分类
        $(".industrysPackageSearchAll").click(function () {
            industry = 0;
            var url = "/search-all/?keyWords="+keyWords+"&principal="+principal+'&category='+zichanbaobei+"&packageState="+dangqianzhuangtai+"&packageType="+zichanleixing+"&owner="+shangchuanren+"&teams="+tuandui+"&leader="+zongjian+"&province="+province+"&city="+city+'&limit='+pageNumThis+'&industry='+industry+'&order='+orderP+'&entry=sala&postion=2'+'&is_title='+is_title;
            window.location.href = url;
        })
        //--------------end-----------fly----------------------
    })
</script>